<?php

defined('BASEPATH') OR exit('No direct script access allowed');

class Balance extends ZhiyeAdmin_Controller {

    public function __construct(){

        parent::__construct();

		$this->load->model('balance_model','balance');

    }

	public function index(){
        $search["account"]=$_GET['account'];
		$where=array();
		if($search["account"]!=""){
			array_push($where,"account like '%".$search["account"]."%'");
		}
		if($search["submit"]==""){
			array_push($where,"balance.is_delete =0");
		}
		$page_no = max(intval($page_no),1);
		$this->balance->order('id DESC');
		if(count($where)>0)
			$this->balance->where($where);
        $data=$this->balance
						 ->select_all("balance.*",null,null,true,$page_no,"balance");
		$data['moudle_name']="余额管理";
		$data['table_name']="Balance";

		//p($data);die();
		$data['pages']=$this->balance->pages($data["total_num"]);
		$data['search']=$search;

        $this->zhiyeAdmin_view("lists", $data);		
        
    }

    public function edit($id=0){
		$data['moudle_name']="余额信息";
		$data['table_name']="Balance";

		if($id>0){
			$data["balance"]=$this->balance->select_one($id);
        }
        $this->zhiyeAdmin_view('edit',$data);
        
	}
	public function update($id=0){
		$balance=$this->input->post('balance');
		if($id>0){
			$this->balance->update($balance, array('id='.$id));
		}else{
			$this->balance->insert($balance);
		}
		redirect('admin/balance/index');
	}

    public function delete($checkIds=0){
		$checkIds=$_GET['checkIds'];
		//$str = 'apple,banana';
		$ids = explode(',', $checkIds);
		foreach ( $ids as $id )
		{
			if($id!=''){
				$this->balance->delete_one($id);
			}
			echo $id;
		}
		redirect('admin/balance/index');
	}
}